<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8" />
    <title>牛牛-商户管理</title>

    <meta name="description" content="Dashboard" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/resource/assets/img/favicon.png" type="image/x-icon">

    <!--Basic Styles-->
    <link href="${pageContext.request.contextPath}/resource/assets/css/bootstrap.min.css" rel="stylesheet" />
    <link href="${pageContext.request.contextPath}/resource/assets/css/font-awesome.min.css" rel="stylesheet" />

    <!--Beyond styles-->
    <link href="${pageContext.request.contextPath}/resource/assets/css/beyond.min.css" rel="stylesheet" type="text/css" />
    <link href="${pageContext.request.contextPath}/resource/assets/css/animate.min.css" rel="stylesheet" />
<script src="${pageContext.request.contextPath}/resource/assets/js/skins.min.js"></script>
</head>
<body>
<%@include file="../header.jsp" %>
	<!-- Main Container -->
    <div class="main-container container-fluid">
        <!-- Page Container -->
        <div class="page-container">
            <!-- Page Sidebar -->
            <%@include file="../manager/nav.jsp" %><!-- /Page Sidebar -->
            <!-- Page Content -->
            <div class="page-content">
                <!-- Page Breadcrumb -->
                <div class="page-breadcrumbs">
                    <ul class="breadcrumb" style="margin-top: 8px;">
                        <li>
                            <i class="fa fa-home"></i>
                            <a href="#">牛牛</a>
                        </li>
                        <li><a href="#">商户管理</a></li>
                        <li class="active">添加商户</li>
                    </ul>
                </div><!-- /Page Breadcrumb -->
                <!-- Page Header -->
                <div class="page-header position-relative">
                    <div class="header-title" style="margin-top: 2px;">
                        <h1>
                            添加商户
                        </h1>
                    </div><!--Header Buttons-->
                    <div class="header-buttons">
                        <a class="sidebar-toggler" href="#">
                            <i class="fa fa-arrows-h"></i>
                        </a>
                        <a class="refresh" id="refresh-toggler" href="">
                            <i class="glyphicon glyphicon-refresh"></i>
                        </a>
                        <a class="fullscreen" id="fullscreen-toggler" href="#">
                            <i class="glyphicon glyphicon-fullscreen"></i>
                        </a>
                    </div><!--Header Buttons End-->
                </div><!-- /Page Header -->
                <!-- Page Body -->
                <div class="page-body">
                	<div class="row">
	                	<div class="col-lg-6 col-sm-6 col-xs-12">
	                		<div class="widget">
                                        <div class="widget-header bordered-bottom bordered-palegreen">
                                            <span class="widget-caption">添加新商户</span>
                                        </div>
                                        <div class="widget-body">
                                           <div id="registration-form">
                                                        <form role="form">
                                                            <div class="form-title">
                                                            	商户信息
                                                            </div>
                                                            <div class="form-group">
                                                                <span class="input-icon icon-right">
                                                                    <input id="name" type="text" class="form-control"  placeholder="商户名称">
                                                                    <i class="glyphicon glyphicon-user circular"></i>
                                                                </span>
                                                            </div>
                                                            
                                                            <div class="form-group">
                                                                        <select id="type" name="type" style="width:100%;">
                                                                        		<option value="0">请选择商户类型</option>
                                                                        		<option value="1">超市</option>
                                                                        		<option value="2">爱车</option>
                                                                        		<option value="3">水果</option>
                                                                        		<option value="4">培训</option>
                                                                        		<option value="5">眼镜</option>
                                                                        		<option value="6">旅游</option>
                                                                        		<option value="20">其他</option>
                                            							</select>
                                                              </div>
                                                            
                                                            <div class="form-group">
                                                                <span class="input-icon icon-right">
                                                                    <input id="address" type="text" class="form-control"  placeholder="商户地址">
                                                                    <i class="fa fa-lock circular"></i>
                                                                </span>
                                                            </div>
                                                            <div class="form-group">
                                                                <span class="input-icon icon-right">
                                                                    <input id="contacts" type="text" class="form-control"  placeholder="联系人">
                                                                    <i class="fa fa-lock circular"></i>
                                                                </span>
                                                            </div>
                                                             <div class="form-group">
                                                                <span class="input-icon icon-right">
                                                                    <input id="tel" type="text" class="form-control"  placeholder="联系电话">
                                                                    <i class="glyphicon glyphicon-user circular"></i>
                                                                </span>
                                                            </div>
                                                            <div class="form-group">
                                                                <span class="input-icon icon-right">
                                                                    <input id="scale" type="text" class="form-control"  placeholder="积分比例">
                                                                    <i class="glyphicon glyphicon-user circular"></i>
                                                                </span>
                                                            </div>
                                                            <div class="form-title">
                                                               	 登录信息
                                                            </div>
                                                            <div class="form-group">
                                                                <span class="input-icon icon-right">
                                                                    <input id="username" type="text" class="form-control"  placeholder="用户名 (请填写手机号码)">
                                                                    <i class="glyphicon glyphicon-user circular"></i>
                                                                </span>
                                                            </div>
                                                            
                                                            <div class="form-group">
                                                                <span class="input-icon icon-right">
                                                                    <input id="password" type="password" class="form-control"  placeholder="密码">
                                                                    <i class="fa fa-lock circular"></i>
                                                                </span>
                                                            </div>
                                                           <div class="form-group">
                                                                <span class="input-icon icon-right">
                                                                    <input id="repassword" type="text" class="form-control"  placeholder="确认密码">
                                                                    <i class="fa fa-lock circular"></i>
                                                                </span>
                                                            </div> 
                                                            <hr class="wide" />
                                                            <div class="row" style="text-align: right;margin-right: 10px;">
                                                            	<button type="button" class="btn btn-warning" onclick="cancel()"> 取 消 </button>
                                                            	<button type="button" class="btn btn-blue" onclick="save()"> 确 定 </button>
                                                            </div>
                                                            
                                                        </form>
                                                    </div> 
                                        </div>
                                    </div>
	                	</div>
                	
                    </div>
                </div><!-- /Page Body -->
             </div><!-- /Page Content -->
     	</div><!-- /Page Container -->
     </div><!-- /Main Container -->
     	<script src="${pageContext.request.contextPath}/resource/assets/js/jquery-2.0.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/resource/assets/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/resource/assets/js/beyond.min.js"></script>
    <script src="${pageContext.request.contextPath}/resource/assets/js/select2/select2.js"></script>
<script src="${pageContext.request.contextPath}/resource/assets/js/ajaxfileupload.js"></script>
    <!--Beyond Scripts-->
    
    <script type="text/javascript">
    	$('.loading-container').hide();
    	$('#niuniu').addClass("active open");
    	$('#niuniu_merchant').addClass("active open");
    	$('#niuniu_merchant_add').addClass("active");
    	
    	function save(){
    		var merchantCustom = {};
    		
    		var name = $('#name').val();
    		var username = $('#username').val();
    		var password = $('#password').val();
    		var repassword = $('#repassword').val();
    		var address = $('#address').val();
    		var contacts = $('#contacts').val();
    		var tel = $('#tel').val();
    		var scale = $('#scale').val();
    		var type = $('#type').val();
    		
    		if ($.trim(name) == "" || $.trim(username) == "" || $.trim(password) == "" || $.trim(contacts) == "" || $.trim(tel) == "" || $.trim(scale) == "") {
    			alert("请完善商户信息后再提交保存");
    			return;
    		}
    		
    		if (type == 0) {
				alert("请选择商户类型！");
				return;
			}
    		
    		if (password != repassword) {
				alert("两次输入的密码不一致!");
				return;
			}
    		
    		var reg = /^[+]?[\d]+(([\.]{1}[\d]+)|([\d]*))$/;
    		if(!reg.test(scale)){
    			alert("积分比例格式不符合要求");
    			return;
    		}
    		
    		merchantCustom["name"]=name;
    		merchantCustom["address"]=address;
    		merchantCustom["contacts"]=contacts;
    		merchantCustom["tel"]=tel;
    		merchantCustom["scale"]=scale;
    		merchantCustom["type"]=type;
    		merchantCustom["mUser.username"]=username;
    		merchantCustom["mUser.password"]=password;
    		
    		$('.loading-container').show();
    		$.ajax({
    			url:'${pageContext.request.contextPath}/merchant_save',
    			type:'post',
    			datatype:'json',
    			data:merchantCustom,
    			success:function(resp){
    				if(resp == 200){
    					$('.loading-container').hide();
    					alert("商户信息保存成功！");
    				}
    			}
    		});
    	}
    	
    </script>
</body>
</html>